package com.demo.core.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.demo.base.model.PhoneMsg;
import com.demo.base.util.DateTimeUtil;

@Repository
public class PhoneMsgDao extends BaseDao{

	/**
	 * 查询待发送短信列表（查询前100条记录,只查询当天的）
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<PhoneMsg> listExpectSendSms(){
		
		String nowDate = DateTimeUtil.getNowDateStr(0);
		
		Session session = this.getSession();
		Query query = session.createQuery("from PhoneMsg where flag ='0' and SUBSTRING(recordCreateTime,10) = :nowDate order by ud asc");
		query.setString("nowDate", nowDate);
		query.setMaxResults(100);
		List<PhoneMsg> list = query.list();
		
		return list;
	}
	
	/**
	 * 将今天之前的短信修改成发送失败
	 */
	public void updateYestodayMsg(){
		
		String sql="update phoneMsg set flag='2' where flag='0' and SUBSTRING(recordCreateTime,10)<'"+DateTimeUtil.getNowDateStr(0)+"'";
		Session session = this.getSession();
		session.createQuery(sql).executeUpdate();
	}

}
